package com.lwc.cfdns.controller.admin.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lwc.cfdns.constants.ConstantsUrl;
import com.lwc.cfdns.pojo.bo.system.GroupBO;
import com.lwc.cfdns.pojo.dto.ValidGroup;
import com.lwc.cfdns.pojo.dto.system.GroupDTO;
import com.lwc.cfdns.pojo.entity.SystemGroup;
import com.lwc.cfdns.pojo.vo.system.GroupVO;
import com.lwc.cfdns.service.impl.SystemGroupServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 组合数据接口
 *
 * @author luwc
 * @title GroupController
 * @description
 * @time 2023/7/12 14:38:19
 * @version: 1.0
 */
@RestController
@RequestMapping(ConstantsUrl.ADMIN + "/system")
public class GroupController {
    @Autowired
    private SystemGroupServiceImpl systemGroupService;

    /**
     * 创建
     *
     * @param groupDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 14:44:32
     */
    @PreAuthorize("hasAnyAuthority('system:group:create')")
    @PostMapping("/group")
    public Map<String, Object> create(@Validated(ValidGroup.Create.class) @RequestBody GroupDTO groupDTO) {
        return systemGroupService.create(groupDTO);
    }

    /**
     * 修改
     *
     * @param groupDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 14:48:41
     */
    @PreAuthorize("hasAnyAuthority('system:group:update')")
    @PutMapping("/group")
    public Map<String, Object> update(@Validated(ValidGroup.Update.class) @RequestBody GroupDTO groupDTO) {
        return systemGroupService.update(groupDTO);
    }

    /**
     * 详情
     *
     * @param id
     * @return GroupVO
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 14:55:26
     */
//    @PreAuthorize("hasAnyAuthority('system:group:view')")
    @GetMapping("/group/{id}")
    public GroupVO view(@PathVariable("id") @NotNull(message = "ID不能为空") Long id) {
        return systemGroupService.view(id);
    }

    /**
     * 删除
     *
     * @param ids
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 14:57:35
     */
    @PreAuthorize("hasAnyAuthority('system:group:delete')")
    @DeleteMapping("/group/{ids}")
    public Map<String, Object> delete(@PathVariable("ids") @NotNull(message = "ids不能为空") String ids) {
        return systemGroupService.delete(ids);
    }

    /**
     * 列表
     *
     * @param groupBO
     * @return IPage<SystemGroup>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 14:59:54
     */
    @PreAuthorize("hasAnyAuthority('system:group:lists')")
    @GetMapping("/group")
    public IPage<SystemGroup> lists(GroupBO groupBO) {
        return systemGroupService.lists(groupBO);
    }
}
